home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / DB_CLIPP / 2510.ZIP / TRSOURCE.EXE / TR_INMTH.PRG < prev    next >
Text File  |  1990-10-22  |  2KB  |  49 lines

  1. *********
  2. * Function : INMONTHS
  3. * By : Tom Rettig
  4. * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
  5. *********
  6.  
  7.  
  8. FUNCTION INMONTHS
  9. * Syntax: INMONTHS( <start date>, <end date> )
  10. * Return: <expN> number of months between two dates
  11. * Note..: Both parameters are <expD>
  12. *         Result is affected by the current state of SET DECIMALS
  13. *
  14. PARAMETERS tr_start, tr_end
  15. DO CASE
  16.    CASE tr_start > tr_end
  17.       * Error -- start date is greater than end date
  18.       RETURN -1
  19.    CASE MONTH(tr_start) == MONTH(tr_end) .and. YEAR(tr_start) == YEAR(tr_end)
  20.       * Start and end dates are the same month and year
  21.       RETURN ( DAY(tr_end) - DAY(tr_start) + 1 ) ;
  22.              / LASTDAY(MONTH(tr_end), YEAR(tr_end))
  23.    OTHERWISE
  24.       * Start and end dates are different MONTHs and/or years
  25.       PRIVATE tr_month
  26.       IF YEAR(tr_start) == YEAR(tr_end)
  27.          tr_month = ( MONTH(tr_end) - MONTH(tr_start) ) - 1
  28.       else
  29.          * Get months from first and last years
  30.          tr_month = ( 12 - MONTH(tr_start) ) + ( MONTH(tr_end) - 1 )
  31.          * Add in between years if any
  32.          IF YEAR(tr_end) - YEAR(tr_start) > 1
  33.             tr_month = tr_month + ( 12 * ( YEAR(tr_end) - YEAR(tr_start) - 1))
  34.          ENDIF
  35.       ENDIF
  36.       RETURN ( (LASTDAY(MONTH(tr_start), YEAR(tr_start)) - (DAY(tr_start)-1));
  37.                / LASTDAY(MONTH(tr_start), YEAR(tr_start))) + tr_month +;
  38.              ( DAY(tr_end) / LASTDAY(MONTH(tr_end), YEAR(tr_end)) )
  39.       * Return statement is based on:
  40.       * first month = ((LASTDAY(MONTH(tr_start), YEAR(tr_start)) ;
  41.       *              -(DAY(tr_start)-1))/LASTDAY(MONTH(tr_start),;
  42.       *               YEAR(tr_start)))
  43.       * in between months = tr_month
  44.       * last month = ( DAY(tr_end) / LASTDAY(MONTH(tr_end), YEAR(tr_end)) )
  45. ENDCASE
  46. * eofunc inmonths
  47.  
  48.  
  49.